package com.evola.dbsm.utils
{
	import com.evola.dbsm.model.BaseBean;

	import mx.collections.IList;

	public class ListUtils
	{

		public static function replaceBean(collection:IList, bean:BaseBean):void
		{

			var index:int=getBeanIndex(collection, bean);

			if (index >= 0)
			{
				collection.removeItemAt(index);
				collection.addItemAt(bean, index);
			}
		}
		
		public static function removeBean(collection:IList, bean:BaseBean):void
		{
			
			var index:int=getBeanIndex(collection, bean);
			
			if (index >= 0)
			{
				collection.removeItemAt(index);
			}
		}

		public static function getBeanIndex(collection:IList, bean:BaseBean):int
		{

			var index:int=-1;
			var db:BaseBean;

			for (var i:int=0; i < collection.length; i++)
			{

				db=collection.getItemAt(i) as BaseBean;

				if (db.id == bean.id)
				{
					index=i;
					break;
				}
			}

			return index;
		}


	}
}
